package com.peng.zookeeper;

import java.util.Random;

public class ZKClientTest {

	public static void main(String[] args) {
		String rootPath = "/pay";

		// ZKOperate操作
		ZKOperate zkWatchAPI = new ZKOperate();

		// 连接zk服务器
		MyZooKeeper zooKeeper = new MyZooKeeper();
		zooKeeper.connect("118.24.173.91:2181");

		int ip_1 = new Random().nextInt(155) + 100;
		int ip_2 = new Random().nextInt(255);
		int ip_3 = new Random().nextInt(255);
		int ip_4 = new Random().nextInt(255);
		int port = new Random().nextInt(64511) + 1024;

		String input = rootPath + "/" + ip_1 + "." + ip_2 + "." + ip_3 + "." + ip_4 + ":" + port;

		// 创建节点数据
		if (zkWatchAPI.createZNode(input, input.split("/")[2])) {
			System.out.println("节点[" + rootPath + "]数据内容[" + zkWatchAPI.readData(rootPath) + "]");
		}
		String data = zkWatchAPI.readData(input);
		System.out.println("数据：" + data);

		zooKeeper.close();
	}
}